import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/model/pay_model/bill_page_model.dart';
import 'package:yysk_app/model/pay_model/page_with_draw_list_model.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/widget/custom_app_bar2.dart';
import 'package:yysk_app/widget/image_asset_widget.dart';
import 'package:yysk_app/widget/refresh_and_scroll_widget.dart';
import 'withdraw_record_controller.dart';

class WithdrawRecordPage extends GetView<WithdrawRecordController> {
  static const path = '/withdrawRecord';
  const WithdrawRecordPage({super.key});

  Color _statusColor(String status) {
    switch (status) {
      case 'SUCCESS':
        return AppColors.fontColorGreen00;
      case 'FAILURE':
        return AppColors.fontColorRed2;
      case 'PROCESSING':
        return AppColors.fontColor;
      default:
        return AppColors.fontColor;
    }
  }

  @override
  Widget build(BuildContext context) {
    final double top = MediaQuery.of(context).padding.top;
    final ScrollController scrollController = ScrollController();
    return Scaffold(
      // backgroundColor: AppColors.backgroundColorBlack,
      body: Stack(
        children: [
          Positioned(
            top: 0,
            left: 0,
            right: 0,
            child: ImageAssetWidget(
              width: 375.px,
              height: 812.px,
              imageUrl: 'static/images/bg.png',
            ),
          ),
          Padding(
            padding: EdgeInsets.fromLTRB(0, top, 0, 24.px),
            child: Column(
              children: [
                CustomAppBar2(title: '提现记录', context: context),
                Expanded(
                  child: Obx(
                    () => Padding(
                      padding: EdgeInsets.fromLTRB(16.px, 20.px, 16.px, 20.px),
                      child: RefreshAndScrollWidget(
                        onRefresh: _handleRefresh,
                        scrollController: scrollController,
                        itemBuilder:
                            (item, index) =>
                                _itemRecord(context: context, item: item),
                        itemCount: controller.withDrawRecordList.length,
                        items: controller.withDrawRecordList,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  _handleRefresh() {
    controller.getWithdrawRecord();
  }

  _itemRecord({
    required BuildContext context,
    required PathWithDrawListItemModel item,
  }) {
    return Container(
      padding: EdgeInsets.fromLTRB(14.px, 12.px, 14.px, 12.px),
      margin: EdgeInsets.only(bottom: 8.px),
      decoration: BoxDecoration(
        color: AppColors.backgroundColorBlackLight,
        borderRadius: BorderRadius.circular(10.px),
        border: Border.all(
          width: 1.px,
          color: Color.fromRGBO(255, 255, 255, 0.1),
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      '${item.statusDesc}',
                      style: TextStyle(
                        fontSize: 14.px,
                        fontWeight: FontWeight.bold,
                        color: _statusColor(item.status!),
                      ),
                    ),
                    SizedBox(height: 10.px),
                    Text(
                      '${item.createTime}',
                      style: TextStyle(
                        fontSize: 12.px,
                        color: AppColors.fontColorGray99,
                      ),
                    ),
                  ],
                ),
              ),
              Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(
                    '-￥',
                    style: TextStyle(
                      fontSize: 14.px,
                      color: AppColors.fontColor,
                    ),
                  ),
                  Text(
                    '${item.amount}',
                    style: TextStyle(
                      fontSize: 14.px,
                      fontWeight: FontWeight.bold,
                      color: AppColors.fontColor,
                    ),
                    textAlign: TextAlign.end,
                  ),
                ],
              ),
            ],
          ),
          item.status == 'FAILURE' || item.status == 'REFUSE'
              ? hiSpace(height: 10.px)
              : SizedBox(),
          item.status == 'FAILURE' || item.status == 'REFUSE'
              ? Container(
                constraints: BoxConstraints(maxWidth: context.width - 30),
                child: Text(
                  '原因：${item.reason ?? '暂无'}',
                  style: TextStyle(
                    fontSize: 12.px,
                    color: AppColors.fontColorRed2,
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
              )
              : SizedBox(),
        ],
      ),
    );
  }
}
